<template>
  <div class="container">
    <el-row class="mb10">
      <el-col :span="15" align="left">
        <div class="flex">
          <el-input clearable v-model="searchParams.projectname" placeholder="项目名称"
            style="width: 120px; margin-right: 15px">
          </el-input>

          <el-input clearable v-model="searchParams.applicationunit" placeholder="申报单位/项目负责人"
            style="width: 180px; margin-right: 15px">
          </el-input>

          <el-select clearable v-model="searchParams.completionperiod" placeholder="完成年限">
            <el-option :label="item.itemName" :value="item.itemValue" :key="item.itemValue"
              v-for="item in options.yearList" />
          </el-select>

          <el-date-picker style="width: 233px; margin-right: 15px" v-model="data.time" type="daterange"
            range-separator="-" start-placeholder="申报开始日期" end-placeholder="申报结束日期" @change="dataPickerChange">
          </el-date-picker>

<!--
          <el-select clearable v-model="searchParams.status" placeholder="状态">
            <el-option :label="item.itemName" :value="item.itemValue" :key="item.itemValue"
              v-for="item in options.statusDate" />
          </el-select>
-->
          <el-select  v-model="data.statusUpdate" placeholder="状态">
            <el-option
                :label="item.itemName"
                :value="item.itemValue"
                :key="item.itemValue"
                v-for="item in options.statusDate"
            />
          </el-select>

          <el-button color="#626aef" @click="getListData" class="ordinary">搜索</el-button>
        </div>
      </el-col>
      <el-col :span="9" align="right">
<!--        <el-button class="ordinary" @click="getExport()" v-limit="'XMZX:KYXMLXPS:XSSC:EXPORT'"> 批量导出</el-button> -->
        <el-button class="ordinary" @click="handleExport()" v-limit="'KJSL:KJJL:YXKJRC:EXPERT'"> 批量导出</el-button>

        <el-button type="primary" @click="handleConfirm()"  v-limit="'XMZX:KYXMLXPS:ZJCS:PREREVCONFIRM'">初审确定</el-button>
        <el-button type="primary" @click="handleSetExpert()" v-limit="'XMZX:KYXMLXPS:ZJCS:SETUPPREREVIEX'">设置初审专家</el-button>
        <el-button type="primary" @click="handleAdd()" v-limit="'XMZX:KYXMLXPS:ZJCS:EXPERTPRELREVI'">专家初审</el-button>
        <el-button type="primary" @click="handleOver()" v-limit="'XMZX:KYXMLXPS:ZJCS:OVOFEXPRRE'">专家初审总览</el-button>
      </el-col>
    </el-row>

<!--
    <Table  :tableArr="data.allTableData" :pagination="data.page1"
        :columns="data.columns" :total="data.page1.total" @delectTable="delectIds"  @row-lclick="onShow">
-->
    <Table :showSize="true" :tableArr="data.allTableData" :pagination="data.page1"  v-loading="data.allTableloading"
        :columns="data.columns" :total="data.page1.total" @delectTable="delectIds" @typesTable="delecttypes"   @row-lclick="handleRowClick" @currentChange ="pageChangetwo" @sizeChange="sizeChange">
        <template #operate="{ row }">
          <el-button type="small" class="ordinary" @click="handleDetail(row)" v-limit="'XMZX:KYXMLXPS:ZJCS:DETAILS'">详情</el-button>
          <el-button type="small"    class="ordinary" @click="handleResult(row)" v-limit="'XMZX:KYXMLXPS:ZJCS:CHECKEXPERTRESULT'">查看专家初审结果</el-button>
        </template>
      </Table>


    <el-dialog v-model="data.detailVisible" :append-to-body="false" width="900px" @close="data.detailVisible = false"
      :show-close="false" :close-on-click-modal="false">
      <template #title>
        <el-descriptions title="详情" border :column="2">
          <el-descriptions-item label="项目名称">{{
            data.detailForm.projectname
          }}</el-descriptions-item>
          <el-descriptions-item label="申报单位">{{
            data.detailForm.applicationunit
          }}</el-descriptions-item>
          <el-descriptions-item label="联系电话">{{
            data.detailForm.telephone
          }}</el-descriptions-item>
          <el-descriptions-item label="完成年限">{{
            data.detailForm.completionperiod
          }}</el-descriptions-item>
          <el-descriptions-item label="总投资(万元)">{{
            data.detailForm.totalinvestment
          }}</el-descriptions-item>
          <el-descriptions-item label="申请中咨(拨款)">{{
            data.detailForm.applyfunding
          }}</el-descriptions-item>
          <el-descriptions-item label="申报日期">{{
            data.detailForm.reporttime
          }}</el-descriptions-item>
        </el-descriptions>
      </template>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="data.detailVisible = false">关闭</el-button>
        </span>
      </template>
    </el-dialog>

    <el-dialog v-model="data.openResult" width="60%" :show-close="true" style="min-height: 200px;" destroy-on-close>
        <ResultView :lookId="data.lookId" :lookId1="data.lookId1"/>
      <template #footer>
        <span style="text-align: center;">
          <el-button @click="closeExvew()">关闭</el-button>
        </span>
      </template>
    </el-dialog>

    <ReviewDialog :dialog="data.examinationVisible" :check-id="data.id" @changeDialog="changeReviewDialog"
      title="初审建议"></ReviewDialog>

    <SetExpertsDialog :checkId="data.id" :dialog="data.expertVisable" @changeDialog="changeExpertDialog"
      title="设置初审专家"></SetExpertsDialog>

    <ResultDialog v-if="data.resultDialog" :checkId="data.id" :dialog="data.resultDialog" @changeDialog="changeResultDialog"
      title="专家评审结果">
    </ResultDialog>

    <OverViewDialog :checkId="data.id" :lookId1="data.lookId1"  :dialog="data.overDialog" @changeDialog="changeOverDialog"
      title="专家初审总览"></OverViewDialog>

    <!-- 导出字段选择 -->
    <Export
        :detailList="data.detailList"
        :showing="data.exportDialog"
        @close="closeExport"
        @handle-filed="handleFiled"
    ></Export>
    <el-dialog v-model="data.detailVisible" :append-to-body="false" width="900px" @close="data.detailVisible = false"
      :show-close="false" :close-on-click-modal="false">

      <div class="my-header">
        <el-tabs v-model="activeName" class="demo-tabs">
          <el-tab-pane :initData="data.initData" label="详情信息" name="first">

            <el-form label-position="top" status-icon>
              <el-row :gutter="20">
                <el-col :span="12">
                  <el-form-item label="项目名称">
                    <el-input placeholder="请输入" disabled v-model="data.detail.projectname" style="width: 100%" />
                  </el-form-item>
                </el-col>

                <el-col :span="12">
                  <el-form-item label="申报单位">

                    <el-input placeholder="请输入" disabled v-model="data.detail.applicationunit" style="width: 100%" />

                  </el-form-item>
                </el-col>

                <el-col :span="12">
                  <el-form-item label="项目负责人">

                    <el-input placeholder="请输入" disabled v-model="data.detail.projectleader" style="width: 100%" />
                  </el-form-item>
                </el-col>

                <el-col :span="12">
                  <el-form-item label="联系电话">
                    <el-input disabled maxlength="11" placeholder="请输入" v-model="data.detail.telephone"
                      style="width: 100%" />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="12">
                  <el-form-item label="完成年限">
                    <el-select disabled v-model="data.detail.completionperiod" placeholder="请选择" style="width: 100%">
                      <el-option :label="item.itemName" :value="item.itemValue" :key="item.itemValue"
                        v-for="item in options.yearList" />
                    </el-select>
                  </el-form-item>
                </el-col>

                <el-col :span="12">
                  <el-form-item label="总投资(万元)">
                    <el-input disabled placeholder="请输入" v-model="data.detail.totalinvestment" style="width: 100%" />
                  </el-form-item>
                </el-col>

                <el-col :span="12">
                  <el-form-item label="申请中咨拨款(万元)">
                    <el-input disabled placeholder="请输入" v-model="data.detail.applyfunding" style="width: 100%" />
                  </el-form-item>
                </el-col>

                <el-col :span="12">
                  <el-form-item label="申报日期">
                    <el-date-picker disabled v-model="data.detail.reporttime" placeholder="选择日期" clearable
                      style="width: 100%" />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row> </el-row>

              <el-form-item label="主要研究内容">
                <el-input disabled v-model="data.detail.researchcontents" :autosize="{ minRows: 2, maxRows: 6 }"
                  type="textarea" placeholder="请输入" />
              </el-form-item>

              <el-form-item label="主要技术经济指标">
                <el-input disabled v-model="data.detail.mainindicators" :autosize="{ minRows: 2, maxRows: 6 }"
                  type="textarea" placeholder="请输入" />
              </el-form-item>

              <el-form-item label="创新点及可能获得的成果和知识产权">
                <el-input disabled v-model="data.detail.describetwo" :autosize="{ minRows: 2, maxRows: 6 }"
                  type="textarea" placeholder="请输入" />
              </el-form-item>

              <el-form-item label="立项背景(包括项目背景、项目概况、研究的必要性等)">
                <el-input disabled v-model="data.detail.backdrop" :autosize="{ minRows: 2, maxRows: 6 }" type="textarea"
                  placeholder="请输入" />
              </el-form-item>

              <el-form-item label="国内外研究概况及可行性分析" prop="analysis">
                <el-input disabled v-model="data.detail.analysis" :autosize="{ minRows: 2, maxRows: 6 }" type="textarea"
                  placeholder="请输入" />
              </el-form-item>

              <el-form-item label="项目研究的主要内容及技术指标(包括要解决的主要技术难点和问题，研究的创新点和内容、主要技术指标及其水平、提交的成果及形式等)">
                <el-input disabled v-model="data.detail.qualification" :autosize="{ minRows: 2, maxRows: 6 }"
                  type="textarea" placeholder="请输入" />
              </el-form-item>

              <el-form-item label="项目研究的技术路线(包括拟采取的技术路线，与后续技术改造或基本建设计划的衔接等)">
                <el-input disabled v-model="data.detail.roadmap" :autosize="{ minRows: 2, maxRows: 6 }" type="textarea"
                  placeholder="请输入" />
              </el-form-item>

              <el-form-item label="推广应用前景及经济效益预测(包括市场需求或推广应用前景、经济效益，形成的生产能力或有关节约工程造价、缩短工期指标等)">
                <el-input disabled v-model="data.detail.forecast" :autosize="{ minRows: 2, maxRows: 6 }" type="textarea"
                  placeholder="请输入" />
              </el-form-item>

              <el-form-item label="申报单位和协作单位及分工(包括项目承担单位、主要协作单位（仅限中咨集团下属单位）简介及分工等)">
                <el-input disabled v-model="data.detail.dividethework" :autosize="{ minRows: 2, maxRows: 6 }"
                  type="textarea" placeholder="请输入" />
              </el-form-item>

              <el-form-item label="项目进度计划(包括年度工作进度安排及完成期限等)(包括项目承担单位、主要协作单位（仅限中咨集团下属单位）简介及分工等)">
                <el-input disabled v-model="data.detail.programme" :autosize="{ minRows: 2, maxRows: 6 }" type="textarea"
                  placeholder="请输入" />
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="项目经费预算" name="second">
            <!-- <BudgettableJson :fatherTableJson="data.tableJson" :addFlag="2" @tableJson="changeBudget" /> -->
            <Budget v-if="data.detailVisible" title="详情" :initData="data.tableJson" @tableJson="changeBudget" />

          </el-tab-pane>
          <el-tab-pane label="相关附件" name="4">
            <PlatformFilesxq :files="data.files" @filesParams="filesParams"   download="KJSL:KJCG:XSLW:DOWNLOAD"  upload="KJSL:KJCG:XSLW:UPLOAD" fileDelete="KJSL:KJCG:XSLW:FILEDELET"></PlatformFilesxq>
          </el-tab-pane>
          <el-tab-pane v-if="data.approvalFormalExamination.modifyUsername" label="审批详情" name="approvalInfo">
              <el-form class="inline-form" label-position="top" status-icon label-width="140px">
                <el-form-item label="审查结果："> {{data.approvalFormalExamination.status}} </el-form-item>
                <el-form-item label="审查人：">  {{data.approvalFormalExamination.modifyUsername}} </el-form-item>
                <el-form-item label="审查时间："> {{data.approvalFormalExamination.reviewtime}} </el-form-item>
                <el-form-item label="审查意见：">
                  <el-input type="textarea" disabled v-model="data.approvalFormalExamination.comment"></el-input>
                </el-form-item>
                <el-form-item label="附件："> 
                  <template v-if="data.approvalFormalExamination.files && data.approvalFormalExamination.files.length" >
                     <div v-for="(file , i) in data.approvalFormalExamination.files" style="margin-right: 10px" :key="'fiels' + i">
                      <el-link type="primary"  :href="file.url" target="_blank">{{file.name}}</el-link>
                     </div>
                  </template>
                </el-form-item>
              </el-form>
          </el-tab-pane>
        </el-tabs>
      </div>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="data.detailVisible = false">关闭</el-button>
        </span>
      </template>


    </el-dialog>
  </div>
</template>
<script lang="ts">
import * as proxy from "@/constants/proxy";
import request from "@/utils/request";
import { getDetailById, getApprovalById, getExportApply } from '@/views/project/api/projectApplication';
import ColumnData from '@/views/science/components/table/column-data.vue';
import Table from '@/views/science/components/table/table.vue';
import {Modals, tips} from "@/views/science/components/tips/tips";
import platformFiles from "@/views/science/technologyStrength/components/platformFiles/platformFiles.vue";
import { ElMessage, ElMessageBox } from "element-plus";
import moment from "moment";
import { ObjectType } from "typings/interfaces";
import { onMounted, reactive, ref } from "vue";
// import Budget from "./components/budget.vue";
import Budget from "@/views/project/components/BudgetTable/budgetTable.vue";
import OverViewDialog from "./components/overViewDialog.vue";
import ResultDialog from "./components/resultDialog.vue";
import ResultView from "./components/resultView.vue";
import ReviewDialog from "./components/reviewDialog.vue";
import SetExpertsDialog from "./components/setExpertsDialog.vue";
import tableData from "./tableHeader.json";
import Export from '@/views/project/components/Export/index.vue'
import {string} from "mathjs";
import {random} from "lodash";
import PlatformFiles from "./platformFiles/platformFiles.vue";
import PlatformFilesxq from "./platformFiles/platformFilesxq.vue";
import {getStatusText} from '@/utils/index'
// import BudgettableJson from "./budgetTable.vue";
export default {
  components: {
    // BudgettableJson,
    PlatformFiles,
    PlatformFilesxq,
    platformFiles,
    Budget,
    ReviewDialog,
    SetExpertsDialog,
    ResultDialog,
    OverViewDialog,
    ColumnData,
    ResultView,
    Table,
    Export,
  },
  props: {
    initData: {
      type: Object,
      required: true,
    },
    initNum: {
      type: Object,
      required: true,
    },
  },
  setup(props) {
    let selectedRows: ObjectType[] = [];
    //列表显示的字段
    //模态框以及信息栏是否显示
    let data = reactive({
      lookId:'',
      lookId1:0,
      id:'',
      openResult:false,
      allTableData: [],
      tableItem: { id: "",type: "",status: "", }, //当前选中的行
      overDialog: false,
      examinationVisible: false,
      expertVisable: false,
      resultDialog: false,
      page1: { page: 1, limit: 10, total: 0 },
      page: 1,
      pageSize: 10,
      total: 0,
      detail: {},
      detailForm: {
        reporttime: null,
      },
      detailVisible: false,
      columns: tableData.lxsqTableHeader,
      time: [],
      initData: {},
      addFlag: 0, //变更记录是否显示
      orgAllList: "",
      recordShow: false,
      dialogVisible: false, //  新增修改确认项目弹框
      persionDialogVisible: false, //  选择参与人员弹框
      reDate: "",
      ruleForm: {
        type: 3,
        applicationunit: "",
        projectleader: "",
      },
      ids:[],
      type:[],
      status:[],
      files: [],
      exportDialog: false,
      detailList: [] as any,
      allTableloading: false,
      statusUpdate:"",//状态判断
      tableJson:[],
      approvalFormalExamination: {
        modifyUsername: '',
        comment: '',
        reviewtime: '',
        status: '',
        files: []
      }
    });
    const closeExport = () => {
      data.exportDialog = false
    }
    const handleFiled = (arr) => {
      console.log(arr, 'handleFiled')
      let sdt = selectArr.map((el) => el.id);
      if (arr.length > 0) {
        ElMessageBox.confirm('您确认导出查询数据吗？', '批量导出', {
          confirmButtonText: '确认',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          // exportProjectList({ ...searchParams, ids: sdt.join(",") , headList: arr }, '科研项目数据表格')
          getExportApply({ ...searchParams, ids: data.ids.map(String) , headList: arr}, "科研项目专家初审");
          console.log('批量导出')
          data.exportDialog = false
        })
      }
    }
    const handleExport = () => {
      data.exportDialog = true
      data.detailList = [
        { fieldName: 'projectname', title: '项目名称' },
        { fieldName: 'applicationunit', title: '申请单位' },
        { fieldName: 'projectleader', title: '项目负责人' },
        { fieldName: 'telephone', title: '联系电话' },
        { fieldName: 'completionperiod', title: '完成年限' },
        { fieldName: 'totalinvestment', title: '总投资(万元)' },
        { fieldName: 'applyfunding', title: '申请中咨拨款（万元）' },
        { fieldName: 'reporttime1', title: '申报日期' },
        { fieldName: 'researchcontents', title: '主要研究内容' },
        { fieldName: 'mainindicators', title: '主要技术经济指标' },
        { fieldName: 'describetwo', title: '创新点及可能获得的成果和知识产权' },
        { fieldName: 'backdrop', title: '立项背景' },
        { fieldName: 'analysis', title: '国内外研究概况及可行性分析' },
        { fieldName: 'qualification', title: '项目研究的主要内容及技术指标' },
        { fieldName: 'roadmap', title: '项目研究的技术路线' },
        { fieldName: 'forecast', title: '推广应用前景及经济效益预测' },
        { fieldName: 'dividethework', title: '申报单位和协作单位及分工' },
        { fieldName: 'programme', title: '项目进度计划' },
      ]
    }

    let selectArr: Config[] = reactive([]);

    const handleSelectionChange = (val) => {
      selectArr = val;
    };
    let loading = ref(true);
    // 查询参数
    let searchParams = reactive({
      type: 3,
      typeParams: 1,
      startTime: null,
      endTime: null,
    }) as any;
    //进入获取表单数据

    //单选
    const selectTable = (e, row, index) => {
      const data1 = data.allTableData;
      //遍历表格的数据，将非本行的所有数据的checked属性置为false，即取消选择
      for (let i in data1) {
        if (i == index) {
          (data1[i] as any).checked = e;
        } else {
          (data1[i] as any).checked = false;
        }
      }
      data.allTableData = data1;
      if (e) {
        data.tableItem = row;
      } else {
        data.tableItem = { id: "",type: "",status: "", };
      }
    };

    const options: any = reactive({
      yearList: [
        { itemName: "2026年", itemValue: 2026 },
        { itemName: "2025年", itemValue: 2025 },
        { itemName: "2024年", itemValue: 2024 },
        { itemName: "2023年", itemValue: 2023 },
        { itemName: "2022年", itemValue: 2022 },
        { itemName: "2021年", itemValue: 2021 },
        { itemName: "2020年", itemValue: 2020 },
        { itemName: "2019年", itemValue: 2019 },
      ],
      statusDate: [
        { itemName: "全部", itemValue: "10" },
        { itemName: "已选择专家", itemValue: "11" },
        { itemName: "待审查", itemValue: "1" },
        // { itemName: "审查通过", itemValue: "2" },
        { itemName: "审批不通过", itemValue: "3" },
        // { itemName: "审批拒绝", itemValue: "3" },
        { itemName: "立项审查中", itemValue: "6" },
        { itemName: "工作大纲审查中", itemValue: "7" },
        { itemName: "领导班子会审中", itemValue: "8" },
        { itemName: "已批准立项", itemValue: "9" },

      ],
      unitnameList: [],
      affiliationList: [],
      SoftnessList: [],
      classnameList: [],
      competitionclassList: [],
      belongingunitList: [],
      awardList: [],
      zlztList: [],
      jsflList: [],
      // xmlbList: [],
      yhrenList: [],
    });
    const delectIds = (ids) => {
      console.log(1111,ids)
      data.ids = ids
      console.log(2222,data.ids)
      data.id = data.ids.join(',')
      console.log(33333,data.id)
      console.log(44444,data.ids)
    }
    const delecttypes = (types) => {
      console.log(22,types)
      // data.type = types
      // data.type = types.join(',')
      data.type = types
    }
    const delectstatus = (status) => {
      console.log(22,status)
      // data.type = types
      // data.type = types.join(',')
      data.status = status
    }
    const handleSetExpert = () => {

      if (data.ids.length == 0) {
        ElMessage({
          message: "请选择",
          type: "warning",
        });
        return false;
      }
      if (data.ids.length > 1) {
        ElMessage({
          message: "只允许选择一条数据",
          type: "warning",
        });
        return false;
      }
      console.log('type',data.type)
      let panduan = 0 ;
      data.type.forEach(item => {
        for (let i = 0; i <data.type.length; i++) {
          if (item != 3){
            panduan = 1
          }
        }
      });
      if(panduan == 1){
        tips("请选择处于专家初审的一条数据", "warning");
        // event.stopPropagation();
        return false;
      }
      let statusduan = 0 ;
      data.type.forEach(item => {
        for (let i = 0; i <data.status.length; i++) {
          if (item != 3){
            statusduan = 1
          }
        }
      });
      if(statusduan == 1){
        tips("请选择处于待审查的一条数据", "warning");
        // event.stopPropagation();
        return false;
      }

      // data.id=data.tableItem.id
      data.id = data.ids.join(',')


      data.expertVisable = true;
    };

    const changeExpertDialog = () => {
      getListData();
      data.expertVisable = false;

    };

    const changeResultDialog = () => {

      getListData()
      data.resultDialog = false;
    };

    const changeOverDialog = () => {
      data.overDialog = false;
    };

    // 清除日期选择器,删除的时候将日期清空
    const dataPickerChange = () => {
      if (data.time) {
        searchParams.startTime = data.time[0];
        searchParams.endTime = data.time[1];
      } else {
        searchParams.startTime = null;
        searchParams.endTime = null;
        data.time = [];
      }
    };

    const changeUnit = (val) => {
      let itemText = options.belongingunitList.find((item) => item.id == val).name;
      data.ruleForm.applicationunit = itemText;
    };

    const changeProject = (val) => {
      let itemText = options.yhrenList.find((item) => item.userId == val).username;
      data.ruleForm.projectleader = itemText;
    };

    const pageChange = (current) => {
      data.page = current;
      getListData();
    };

    // 专家初审
    const changeReviewDialog = () => {
      data.examinationVisible = false;
    };

    const getListData = async () => {
      selectArr = [];
      loading.value = true;
      data.allTableloading = true;
      if(data.statusUpdate == "1"){
        searchParams.type=3;
        searchParams.status =1;
        searchParams.typeParams=0;
      } else if (data.statusUpdate =="2"){
        searchParams.type=3;
        searchParams.status=2;
        searchParams.typeParams=0;
      } else if (data.statusUpdate =="3"){
        searchParams.type=3;
        searchParams.status=3;
        searchParams.typeParams=3;
      } else if (data.statusUpdate =="11"){
        searchParams.type=3;
        searchParams.status=8;
        searchParams.typeParams=0;
      }else if (data.statusUpdate =="6"){
        searchParams.type=4;
        searchParams.status=1;
        searchParams.typeParams=0;
      } else if (data.statusUpdate =="7"){
        searchParams.type=5;
        searchParams.status=1;
        searchParams.typeParams=0;
      } else if (data.statusUpdate =="8"){
        searchParams.type=6;
        searchParams.status=1;
        searchParams.typeParams=0;
      } else if (data.statusUpdate =="9"){
        searchParams.type=7;
        searchParams.status=2;
        searchParams.typeParams=0;
      } else if (data.statusUpdate =="10"){
        searchParams.type=3;
        searchParams.typeParams=1;
        delete searchParams.status;

      }

      return request({
        url: proxy.CHECC_API_CMS + "/xmzx/kyxmlxps/approvalApplication/getTotalList",
        method: "post",
        data: {
          ...searchParams,
          page: data.page,
          pageSize: data.pageSize,
        },
      })
        .then((res) => {
          let resData = res.data.data.records;
          //草稿、待审批、审批通过、审批拒绝
          resData.map((item) => {
            if (item.status == 1 && item.type == 3) {
              item.state = "待审查";
            } else if (item.status == 2 && item.type == 3) {
              item.state = "审批通过";
            } else if (item.status == 3 && item.type == 3) {
              item.state = "审核不通过";
            } else if (item.status == 8 && item.type == 3) {
              item.state = "已选择专家";
            } else if (item.status == 1 && item.type == 4) {
              item.state = "立项审查中";
            } else if (item.status == 3 && item.type == 4) {
              item.state = "立项审查不通过";
            } else if (item.status == 1 && item.type == 5) {
              item.state = "工作大纲审查中";
            } else if (item.status == 4 && item.type == 5) {
              item.state = "工作大纲审查中";
            } else if (item.status == 5 && item.type == 5) {
              item.state = "工作大纲审查中";
            }  else if (item.status == 3 && item.type == 5) {
              item.state = "工作大纲审查不通过";
            } else if (item.status == 1 && item.type == 6) {
              item.state = "领导班子会审中";
            } else if (item.status == 3 && item.type == 6) {
              item.state = "领导班子会审不通过";
            } else if (item.status == 1 && item.type == 7) {
              item.state = "批准立项中";
            } else if (item.status == 2 && item.type == 7) {
              item.state = "已批准立项";
            } else if (item.status == 3 && item.type == 7) {
              item.state = "批准立项不通过";
            }

            if (item) {
              item.reporttimeFormat = moment(item.reporttime).format("YYYY-MM-DD");
              item.expertname =   item.expertname || '无';
            }

            //给数据添加checked属性并默认置为false
            for (let index in res.data.data.records) {
              res.data.data.records[index].checked = false;
            }
          });
          data.allTableData = res.data.data.records;
          data.allTableloading = false;
          data.total = res.data.data.total;
          data.page1.total = res.data.data.total;
          data.ids = []
        })
        .finally(() => {
          loading.value = false;
          data.allTableloading = false;
        });
    };
    getListData();
    //主页面表格初始化

    //新增
    const ruleFormRef = ref();
    //新增按钮
    const handleAdd = () => {
      if (data.ids.length < 1) {
        ElMessage({
          message: "请选择一条数据",
          type: "warning",
        });
        return false;
      }
      console.log('type',data.type)
      let panduan = 0 ;
      data.type.forEach(item => {
        for (let i = 0; i <data.type.length; i++) {
          if (item != 3){
            panduan = 1
          }
        }
      });
      if(panduan == 1){
        tips("请选择处于专家初审的一条数据", "warning");
        // event.stopPropagation();
        return false;
      }
      data.examinationVisible = true;
    };


    // 专家初审总览


    const handleOver = () => {
      data.lookId1 = random(1,1000);
      data.overDialog = true;
    };

    const handleClose = () => {
      for (let key in data.ruleForm) {
        data.ruleForm[key] = "";
      }
    };

    const handleConfirm = () => {
      // if (!data.tableItem.id) {
      //   ElMessage({
      //     message: "请选择",
      //     type: "warning",
      //   });
      //   return false;
      // }
      if (data.ids.length < 1) {
        ElMessage({
          message: "请选择",
          type: "warning",
        });
        return false;
      }
      console.log('type',data.type)
      let panduan = 0 ;
      data.type.forEach(item => {
        for (let i = 0; i <data.type.length; i++) {
          if (item != 3){
            panduan = 1
          }
        }
      });
      if(panduan == 1){
        tips("请选择处于专家初审的一条数据", "warning");
        // event.stopPropagation();
        return false;
      }


          /*      if (data.type != '3') {
                  ElMessage({
                    message: "请选择处于专家初审的一条数据",
                    type: "warning",
                  });
                  return false
                }*/

      // data.id=data.tableItem.id
      data.id = data.ids.join(',')
      data.resultDialog = true;

    };
    // 判断
    const rules = reactive({

      projectname: [{ required: true, message: "请输入项目名称", trigger: "blur" }],

      applicationunitid: [

        { required: true, message: "请选择申报单位", trigger: "change" },

      ],

      projectleaderid: [

        { required: true, message: "请选择项目负责人", trigger: "change" },

      ],

      telephone: [{ required: true, message: "请输入联系电话", trigger: "blur" }],

      completionperiod: [
        { required: true, message: "请选择完成年限", trigger: "change" },
      ],

      totalinvestment: [
        { required: true, message: "请输入总投资(万元)", trigger: "change" },
      ],

      applyfunding: [
        { required: true, message: "申请中咨拨款(万元)", trigger: "change" },
      ],

      reporttime: [{ required: true, message: "请选择申报日期", trigger: "change" }],
      status: [{ required: true, message: "请选择状态", trigger: "change" }],
    });
    const ruleForm = reactive({});
    // 保存按钮
    const submitForm = async () => {
      await ruleFormRef.value.validate((valid) => {
        if (valid) {
          const config: Record<string, any> = {
            info: {
              ...data.ruleForm,
            },
          };
          loading.value = true;
          return request({
            url:
              proxy.CHECC_API_CMS +
              `/xmzx/kyxmlxps/approvalApplication/${editId ? "update" : "insert"}`,
            method: "post",
            data: config,
          }).then(() => {
            getListData();
            data.dialogVisible = false;
            return ElMessage({
              message: "操作成功",
              type: "success",
            });
          });
        }
      });
    };

    const handleEditItem = (row) => {
      row.isEdit = true;
    };
    const cancelItem = (row) => {
      row.isEdit = false;
    };

    //编辑按钮
    let editId = "";
    const handleEdit = (row) => {
      editId = row.id;
      // 浅拷贝 row
      data.ruleForm = Object.assign({}, row);

      data.addFlag = 1;

      data.dialogVisible = true;
    };
    const handleRowClick = (row) => {
      handleDetail(row)
    }
    const onShow = (row) => {
      handleDetail(row)
    }
    //确认按钮
    let handleDetail = async (row) => {
      data.allTableloading = true;
      activeName.value = "first";
      getApprovalById(row.id).then(arew => {
        if(arew.data.success) {
          let item = arew.data.data.approvalFormalExamination
          if(item) {
            let file = item.examinationurl ? JSON.parse(item.examinationurl) : []
            item.reviewtime = moment(item.reviewtime).format('YYYY-MM-DD hh:mm:ss')
            item.files = file
            if(item.status === 3  && item.type === '1') {
                data.approvalFormalExamination = {
                modifyUsername: '',
                comment: '',
                reviewtime: '',
                status: '',
                files: []
              }
            } else {
              data.approvalFormalExamination = item
              data.approvalFormalExamination.status = getStatusText([Number(item.status), Number(item.type)])
            }
          } else {
            data.approvalFormalExamination = {
              modifyUsername: '',
              comment: '',
              reviewtime: '',
              status: '',
              files: []
            }
          }
      
        }
      })
      let res = await getDetailById(row.id)
      
      data.allTableloading = false;
      if (res.data.success) {

        data.detail = res.data.data.info
        data.tableJson = res.data.data.contractBudgetList
        data.files= res.data.data.files

        data.detailVisible = true;
      }
    };

    let  handleResult=(row)=>{
      data.lookId = "";
      data.lookId1 = random(1,1000);
      data.openResult = true;
      data.lookId = row.id


    }

    let deleteList = () => {
      if (!selectArr.length) {
        ElMessage({
          message: "请选择",
          type: "warning",
        });
        return;
      }
      ElMessageBox.confirm("是否删除选择内容", "提示", {
        type: "warning",
      })
        .then(() => {
          loading.value = true;
          let sdt = selectArr.map((el) => el.id);
          return request({
            url: proxy.CHECC_API_CMS + `/xmzx/kyxmlxps/approvalApplication/delete`,
            method: "post",
            params: {
              id: sdt.join(","),
            },
          }).then(() => {
            ElMessage({
              message: "删除成功",
              type: "success",
            });
            selectArr = [];
            getListData();
          });
        })
        .catch(() => {
          console.log("点击了取消");
        });
    };


    const getExport = async () => {
      Modals('是否导出全部数据', '提示', 'warning').then(async () => {
        await getExportApply(searchParams, '专家初审')
      }).catch(() => {
        console.log("点击了取消")
      })
    };
    //page分页
    let getpageData = () => {
      selectArr = [];
      getListData();
    };
    const pageChangetwo = (currentChange) => {
      data.page = currentChange;
      data.page1.page = currentChange;

      getListData();
    };
    const sizeChange = (size) => {
      console.log(size)
      data.page1.limit = size
      data.pageSize = size
      getListData()
    }
    // 单位
    const unitname = () => {
      request({
        url: "/checc-api/kgptKjslTchieveSttrans/unitname",
        method: "post",
      }).then((res) => {
        options.unitnameList = res.data.data;
      });
    };
    //承载单位
    const czdw = () => {
      request({
        url: "/checc-api/kjsl/common/getOrgsByLoginUser",
        method: "get",
      }).then((res) => {
        options.belongingunitList = res.data.data;
      });
    };
    //用户单位
    const yonghu = () => {
      request({
        url: "/checc-api/user/getAll",
        method: "get",
      }).then((res) => {
        options.yhrenList = res.data.data;
      });
    };

    // 字段获取
    const affiliation = () => {
      request({
        url: proxy.CHECC_API_CMS + "/dictItem/codelist",
        method: "post",
        data: [
          "KJSL_PATENT_STATUS",
          "KJSL_PATENT_TYPE",
          "KJSL_PATENT_STATUS",
          "KJSL_BUSINESS_SECTOR",
          "KJSL_SOFT_STATE",
        ],
      }).then((res) => {
        options.affiliationList = res.data.data.KJSL_PATENT_STATUS;

        options.competitionclassList = res.data.data.KJSL_PATENT_TYPE;

        options.zlztList = res.data.data.KJSL_PATENT_STATUS;

        options.jsflList = res.data.data.KJSL_BUSINESS_SECTOR;

        options.awardList = res.data.data.KJSL_SOFT_STATE;
      });
    };

    onMounted(() => {
      unitname();
      affiliation();
      // xmlb();
      czdw();
      yonghu();
    });

    //初始页面和数据
    const activeName = ref("first");
    const budgetYear = ref("2023");
    const choosePersion = () => {
      // 选择参与人员按钮事件
      data.persionDialogVisible = true;
    };

    interface Config {
      id: string;
      type: [];
      status: string;

    }

    // 参与人员列表
    let allJoinList = ref([]);
    let searchJoin = reactive({
      name: "", //名称
      unitOrg: "", //机构ID
    });

    const clrJoin = (e) => {
      console.log("删除的参与人员", e);
    };
    const closeExvew = () => {
      getListData();
      data.openResult = false;

    };

    let filesParams = (params) => {
      data.files = params;
    };

    // 预算
    let changeBudget = (parmas) => {
      data.tableJson = parmas.contractBudgetList
    }
    return {
      handleConfirm,
      changeResultDialog,
      changeReviewDialog,
      handleSetExpert,
      changeExpertDialog,
      data,
      changeOverDialog,
      changeUnit,
      dataPickerChange,
      ruleForm, //新增表单数据
      ruleFormRef, //加载表单数据
      rules,
      submitForm, //新增保存
      handleAdd, // 新增
      handleEdit, //编辑
      handleClose,
      handleEditItem,
      cancelItem,
      handleDetail, //确认
      getListData, // 获取列表信息
      getpageData, // 分页信息
      pageChange,
      changeProject,
      deleteList, //删除list
      selectArr, //选择的list
      handleOver,
      getExport,
      options, //维护单位字典
      selectedRows,
      searchParams,
      //下拉选
      unitname,
      selectTable,
      //字段取值
      choosePersion,
      activeName,
      budgetYear,
      allJoinList,
      searchJoin,
      handleSelectionChange,
      handleResult,
      delectIds,
        closeExport,
        handleFiled,
        handleExport,
      handleRowClick,
      onShow,
      pageChangetwo,
      sizeChange,
      delecttypes,
      closeExvew,
      filesParams,
      changeBudget,
    };
  },
};
</script>
<style lang="scss" scoped>
.container {
  background-color: white;
  padding: 20px;
}

.el-col {
  line-height: 40px;
}

.el-form-item {
  .el-input {
    width: 100px;
    background-color: aliceblue;
  }

  .el-select {
    width: 100px;
  }
}

.custom-color {
  color: red !important;
  /* 确保优先级高于其他样式 */
}

.el-table th {
  background-color: #f0f0f0;
  /* 修改表头背景色 */
  color: #333;
  /* 修改表头文字颜色 */
}

:deep(.demo-tabs > .el-tabs__content) {
  max-height: 500px;

  overflow-y: scroll;

  scrollbar-width: none;

  -ms-overflow-style: none;
}

:deep(.el-dialog__header) {
  display: none;
}

.open-title {
  font-size: 20px;
  font-weight: 700;
  text-align: center;
}


.mt15 {
  margin-top: 15px;
}

.mb10 {
  margin-bottom: 10px;
}

.tc {
  text-align: center;
}
.inline-form::v-deep {
  .el-form-item {
    display: flex;
  }
  .el-form-item__label {
    width: 120px;
    text-align: right;
  }
  .el-form-item__content {
    opacity: .8;
  }
}
</style>
